import { http } from '@/utils/request';
import type { Search } from '~/constants/types';

// 添加交易投诉对话
export function addReply(params) {
  return http.request({
    url: `/order/complain/communication`,
    method: "POST",
    params
  });
}

/**
 * 获取投诉详情
 */
export function getComplainDetail(id: string) {
  return http.request({
    url: `/order/complain/${id}`,
    method: "GET",
  });
}

/**
 * 取消投诉
 */
export function clearComplain(id: string) {
  return http.request({
    url: `/order/complain/status/${id}`,
    method: "PUT",
  });
}

/**
 * 添加投诉
 */
export function applyComplain(params: any) {
  return http.request({
    url: `/order/complain`,
    method: "POST",
    header: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
    data: params,
  });
}

/**
 * 审核售后日志
 */
export function getAfterSaleLog(sn: string) {
  return http.request({
    url: `/order/afterSale/get/getAfterSaleLog/${sn}`,
    method: "GET",
  });
}


/**
 * 填充物流信息
 * @param afterSaleSn 售后服务单号
 * @param params 参数信息
 */
export function fillShipInfo(afterSaleSn: string, params: any) {
  return http.request({
    url: `/order/afterSale/delivery/${afterSaleSn}`,
    method: "POST",
    header: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
    data: params,
  });
}


/**
/**
 * 获取商家售后收件地址
 */
export function getStoreAfterSaleAddress(sn: string) {
  return http.request({
    url: `/order/afterSale/getStoreAfterSaleAddress/${sn}`,
    method: "GET",
  });
}

/**
 * 查看售后服务详情
 * @param sn 售后服务单编号
 */
export function getServiceDetail(sn: string) {
  return http.request({
    url: `/order/afterSale/get/${sn}`,
    method: "GET",
  });
}


/**
 * 申请退货服务
 * @param params
 */
export function applyReturn(orderItemSn: string, params: any) {
  return http.request({
    url: `/order/afterSale/save/${orderItemSn}`,
    method: "POST",
    header: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
    data: params,
  });
}


/**
 * 获取申请售后页面信息
 */
export function getAfterSaleInfo(sn: string) {
  return http.request({
    url: `/order/afterSale/applyAfterSaleInfo/${sn}`,
    method: "GET",
  });
}


/**
 * 取消售后
 */
export function cancelAfterSale(afterSaleSn: string) {
  return http.request({
    url: `/order/afterSale/cancel/${afterSaleSn}`,
    method: "POST",
  });
}


/**
 * 获取售后服务记录相关数据
 * @param params 参数
 */
export function getAfterSaleList(params: Search) {
  return http.request({
    url: `/order/afterSale/page`,
    method: "GET",
    params,
  });
}


/**
 * 确认收货
 * @param orderSn 订单编号
 */
export function confirmReceipt(orderSn: string) {
  return http.request({
    url: `/order/order/${orderSn}/receiving`,
    method: "POST",
  });
}

/**
 * 取消订单
 * @param orderSn 订单编号
 * @param reason   取消原因
 */
export function cancelOrder(orderSn: string, reason: any) {
  return http.request({
    url: `/order/order/${orderSn}/cancel`,
    method: "POST",
    header: { "content-type": "application/x-www-form-urlencoded" },
    data: reason,
  });
}

/**
 * 获取取消原因
 */
export function getClearReason(type: string) {
  return http.request({
    url: `/order/afterSale/get/afterSaleReason/${type}`,
    method: "GET",
  });
}
